<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<title>借款申请管理</title>
<link rel="stylesheet" type="text/css" href="${ctx}/styles/ec/ecside_style.css" />
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
</head>
<body>
<div class="x-panel" style="width: 100%">
<div class="x-panel-header">借款申请管理</div>  
<div><%@ include file="/common/messages.jsp"%></div>
<div align="center" style="width: 100%">
<s:form action="save.do" id="save" method="post">
	<s:hidden name="model.id" />
	<table width="75%" border="1" align="center" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-left-width:0px; border-top-width:0px; padding: 4px 2px; margin-top: 10px;">
	<tbody id="tbody">
		<tr height="20" style="padding: 8px 2px;"> 
           <td align="center" colspan="4"><font size="3">借款单</font></td>
        </tr>	
		<tr height="20" style="padding: 10px 2px; padding-left: 22px;">   
           <td align="left" colspan="4">借款部门：
           ${model.dept.name}  
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;借款人：<stc:username></stc:username>
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;借款时间：
           <s:date id="createDate" name="model.createDate" format="yyyy-MM-dd HH:mm"/>
           </td>
        </tr>	
        <tr>
           <td align="right" width="80">借款单号：</td>
           <td align="left" colspan="3">
           		<s:textfield  id="singleNo" name="model.singleNo" cssClass="required" cssStyle="width:135px; border:1px dotted #808080;" ></s:textfield >
           		<font color="red">*</font>
			</td>
        </tr>         
        <tr>
           <td align="right">摘&nbsp;&nbsp;&nbsp;&nbsp;要：</td>
           <td align="left" colspan="3">
           		<s:textfield  id="title" name="model.title" cssClass="required" cssStyle="width:474px; border:1px dotted #808080;" ></s:textfield >
           		<font color="red">*</font>
			</td>
        </tr>        
        <tr height="20">
           <td align="right">项目名称：</td>
           <td align="left" colspan="3" width="720">
                <input type="hidden" id="projectId" name="projectId" value="${model.project.id}">   
                <input type="text" id="projectName"  onclick="openSelect(${model.dept.id})"
                 style="width:474px;border:1px dotted #808080;" value="${model.project.name}"
                 readonly="readonly" >          
			</td>
        </tr>
        
        <tr height="20">
           <td align="right">财务科目：</td>
           <td align="left" width="235">
                <input type="hidden"" id="itemId" name="itemId">    
                <input type="text" id="itemName" onclick="checkSelectItem()" 
                style="width:135px;border:1px dotted #808080;" value="${model.item.name}" 
                readonly="readonly" class ="required">
                <font color="red">*</font>
			</td>
			<td align="right" >金 额：</td> 
			<td ><s:textfield  id="amount" name="model.amount" cssClass="required" onkeyup="yzsz(this)" cssStyle="width:80px; border:1px dotted #808080;" ></s:textfield >
           		<font color="red">*</font>  
			</td>
        </tr>	
		<tr>
			<td align="right">备&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
			<td align="left" colspan="3" style="padding-left: 0px;">
				<textarea id="descn" name="model.descn" style="width: 474px; border:1px dotted #808080;" rows="3" >${model.descn}</textarea>
			</td>
		</tr>
        	
   </tbody>
	</table>

	<table width="600px" style="margin-bottom: 10px;margin-top: 10px;">
		<tr>
			<td style="text-align: center;">
			  <s:submit value="保存" 	cssClass="button" /> 
			  &nbsp;&nbsp;
			  <s:reset value="重置" cssClass="button" />
			</td>
		</tr>
	</table>
</s:form>
</div>
</div>

<script type="text/javascript">
$(document).ready(function(){
	$("#title").focus();
});

$('#amount').keydown(function(e){
	e = window.event || e;
	if(e.keyCode==13 || e.keyCode == 9){
		e.keyCode=9;
	}
});

$(document).ready(function() {
	$("#save").validate();
});

/**
 * 验证借款金额输入的必须是数字
 */
function yzsz(amount){
	if(isNaN(amount.value)||amount.value-0<0){
		alert("请输入数字并且大于0！");
		amount.value="";
		return;
	}
}

function openSelect(id) {
	var url = '${ctx}/base/project/selectGroupProject.do';
	var styles = "dialogWidth:502px; dialogHeight:365px; status:no; scroll:no; help:no";
	document.getElementById("projectId").value = "";
	document.getElementById("projectName").value = "";	
	document.getElementById("itemId").value = "";
	document.getElementById("itemName").value = "";
	var project = window.showModalDialog(url, null, styles);
	if (project != null){
    	document.getElementById("projectId").value = project.id;
    	document.getElementById("projectName").value = project.name;	
    	document.getElementById("itemId").value = "";
    	document.getElementById("itemName").value = "";
		//window.location.href = "edit.do?model.project.id=" + project.id;
	}
}

function checkSelectItem() {
	var projectId = document.getElementById("projectId").value;
	var deptId = '${model.dept.id}';
	if (projectId != null && projectId != "") {
		openSelectItem(projectId, "project");
	}else {
		openSelectItem(deptId, "dept");
	}
}

function openSelectItem(id, type){
	var url = null;
	if(type == "dept"){
		url = '${ctx}/base/item/selectItem.do?dept.id=' + id + '&inputType=radio';
	}else{
		url = '${ctx}/base/item/selectItem.do?project.id=' + id + '&inputType=radio';
	}
	var styles = "dialogWidth:630px; dialogHeight:400px; status:no; scroll:no; help:no";
	var item = window.showModalDialog(url, null, styles);
	if (!item){
		//do nothing...
	}else{
    	document.getElementById("itemId").value = item.id;
    	document.getElementById("itemName").value = item.name;	
		//alert(item.id + ":" + item.name);
	}
}
</script>
</body>
</html>